//
//  PDFShowViewPlugin.m
//  PCDBankSix
//
//  Created by APPLE on 2023/8/23.
//

#import "PDFShowViewPlugin.h"

@implementation PDFShowViewPlugin

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback{
    
    UIViewController *bankWebViewController = context.viewController;
    NSDictionary *dictData = (NSDictionary *)data;
    NSString *strCallback = dictData[@"success"];
    NSString *fileUrl = [PCDUtil safeString:dictData[@"url"]];
    NSString *title = dictData[@"title"];
    NSString *confirmText = [dictData objectForKey:@"confirmText"];
    NSString *cancelText = [dictData objectForKey:@"cancelText"];
    NSString *maxSeconds = [dictData objectForKey:@"maxSeconds"];
//    NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithDictionary:@{
//                @"url":@"https://docs.qq.com/sheet/DVWRwanpwcGtpU2l4?qqapp=docs&entry_scene=1001&adtag=s_wx_mini_docs_1001&applet_id=304b904d-7f8a-4f04-9a5e-056b80880545&tab=000001&_t=1692749049471"}];
    
    NSDictionary  *params = @{@"url":fileUrl};
    if (![PCDUtil nilOrEmptyString:confirmText]) {
        params = @{@"url":fileUrl, @"extraData":@"agreement"};
    }
    
    PCDBankWebViewController *viewController=(PCDBankWebViewController *)[PCDPageViewMangeGet() creatCacheWebController:params View:bankWebViewController Status:NO];
    if (![PCDUtil nilOrEmptyString:title]) {
        viewController.title = title;
    }
    [viewController.bankWebView reload];
    if (![PCDUtil nilOrEmptyString:confirmText]) {
        viewController.isAgreement = YES;
        viewController.cancelBtnTitle = cancelText;
        viewController.agreeBtnTitle = confirmText;
        if (![PCDUtil nilOrEmptyString:maxSeconds]) {
            viewController.maxSeconds = [maxSeconds integerValue];
        }
    }
    __weak typeof(self) tempSelf = self;
    [viewController setBackBlock:^(BOOL status) {
        if (status) {
            NSDictionary *dic = @{
                                   @"confirm":@(YES),
                                   @"cancel":@(NO)
                                   };
            evaluateJavaScriptOnMainThread(self, strCallback, [dic JSONRepresentation]);
        }
    }];
    [bankWebViewController.navigationController pushViewController:viewController animated:YES];
}

@end
